define('common:widget/ui/ai/content/index', function(require, exports, module) {

  /**
   * @file AI工具Content
   * @author yuyanyan01
   */
  
  var san = require('common:widget/ui/ai/san');
  var $ = require('common:widget/ui/base/base');
  var Sider = require('common:widget/ui/ai/sider/sider');
  var ScaleButton = require('common:widget/ui/ai/editButton/scaleButton');
  var ClearButton = require('common:widget/ui/ai/editButton/clearButton');
  var toolButton = require('common:widget/ui/ai/toolButton/toolButton');
  var ButtonNew = require('common:widget/ui/ai/buttonNew/buttonNew');
  var ImgListPreview = require('common:widget/ui/ai/imgListPreview/imgListPreview');
  var ImageEdit = require('common:widget/ui/ai/imageEdit/index');
  var EditGuide = require('common:widget/ui/ai/editGuide/editGuide');
  var Dialog = require('common:widget/ui/ai/dialog/dialog');
  var SendToast = require('common:widget/ui/ai/toast/toast');
  var Loading = require('common:widget/ui/ai/loading/loading');
  var loginPopup = require('common:widget/ui/utils/login');
  var imageEditElement = null;
  var afxPlayer = require('common:widget/ui/ai/afxPlayer/index');
  var PIC_SEARCH_AI_GUIDE = 'pic_search_ai_guide';
  var constants = require('common:widget/ui/utils/constants');
  var buttonType = constants.buttonType;
  var redoToastMap = constants.redoToastMap;
  // 最大历史图片数量
  var MAX_IMAGE_NUM = 20;
  // 单图最大笔触数量
  var MAX_STROKE_NUM = 30;
  // 只保留最近两张图的笔触历史
  var MAX_IMAGE_STROKE_NUM = 2;
  var TOASTMAP = {
      '4': '请选择你要的比例',
      '5': '请涂抹要替换的区域',
      '2': '请涂抹选择你要去除的水印',
      '8': '请涂抹要消除的区域'
  };
  var WATERMARKTOAST = {
      '1': '当前图片检测到多处水印，手动涂抹效果更佳',
      '2': '当前图片没有检测到水印，手动涂抹效果更佳',
      '3': '请涂抹选择你要去除的水印',
  };
  var replaceToastDuration = 4560;
  var removeToastDuration = 4560;
  
  var LOADINGTEXT = {
      '6': '正在重新塑造图片细节',
      '7': '正在生成一系列相似图',
      '8': '正在消除'
  };
  
  var LOADINGTEXT = {
      '1': '正在消除',
      '2': '正在消除',
      '6': '正在重新塑造图片细节',
      '7': '正在生成一系列相似图',
      '8': '正在消除'
  };
  
  var surveyController = require('common:widget/ui/ai/survey/controller');
  var PAGE = require('common:widget/ui/ai/survey/constant');
  
  
  return san.defineComponent({
      template: ''
          +   '<div class="ai-edit-content">'
          +       '<div class="ai-img-container" id="ai-img-container">'
          +           '<div class="ai-img-wrap" style="{{imgWrapStyle}}">'
          +               '<div '
          +                   'class="ai-img-wraper" '
          +               '>'
          +               '</div>'
          +               '<div class="ai-img-replace-guide" s-if="showReplaceAnime">'
          +                   '<afx-player'
          +                       ' afx-url="{{replaceAfxUrl}}"'
          +                       ' is-show="{{true}}"'
          +                       ' should-play="{{true}}"'
          +                       ' hide-bg-url="{{true}}"'
          +                       ' ref-name="editGuide"'
          +                   '/>'
          +               '</div>'
          +               '<div s-if="currentStatus === editStatus.LOADING"'
          +                   'class="ai-img-loading-wrap"'
          +                   'style="width: {{loadingContainerRect.width}}px;'
          +                       'height: {{loadingContainerRect.height}}px;'
          +                       'top: {{selectType === toolTypeMap[toolType.EXPAND]'
          +                           '? 0 : loadingContainerRect.top}}px;'
          +                       'left: {{selectType === toolTypeMap[toolType.EXPAND]'
          +                           '? 0 : loadingContainerRect.left}}px;">'
          +                   '<m-loading '
          +                       'class="ai-img-loading"'
          +                       'progress="{{progress}}"'
          +                       'is-stage="{{isStage}}"'
          +                       'loading-text="{{loadingText}}"/>'
          +               '</div>'
          +           '</div>'
          +           '<div class="ai-edit-guide" s-if="currentStatus !== editStatus.DEFAULT && showEditGuide">'
          +               '<div s-for="item, index in btnList">'
          +                   '<m-edit-guide s-if="item.type === selectType && !item.confirmed"'
          +                       'bg-img-url="{{item.bgImgUrl}}"'
          +                       'afx-url="{{item.guideAfxUrl}}"'
          +                       'afx-back-ups-img-url="{{item.afxBackUpsImgUrl}}"'
          +                       'type="{{item.text}}"'
          +                       'on-close="closeEditGuide"'
          +                   '/>'
          +               '</div>'
          +           '</div>'
          +           '<div class="ai-edit-tool" s-if="{{isShowTool}}">'
          +               '<div s-ref="brushPreview" class="brush-preview" style="{{brushPreviewStyle}}"></div>'
          +               '<div class="left-tool ai-tool-bar">'
          +                   '<m-scaleButton '
          +                       's-if="(selectType !== toolTypeMap[toolType.EXPAND])'
          +                           '|| (selectType === toolTypeMap[toolType.EXPAND]'
          +                               '&& currentStatus === editStatus.COMPLETE)"'
          +                       'class="btn-pointer-event"'
          +                       'finger-selected="{= fingerSelected =}"'
          +                       'scale="{{scale}}"'
          +                       'on-finger-click="handleFingerClick"'
          +                       'on-scale-change="handleScaleChange"'
          +                   '/>'
          +                   '<div class="left-blur-mask tool-blur-mask"></div>'
          +               '</div>'
          +               '<div class="middle-tool">'
          +                   '<m-img-list-preview '
          +                       's-if="currentStatus === editStatus.COMPLETE && imgList && imgList.length"'
          +                       'list="{{imgList}}"'
          +                       'class="btn-pointer-event"'
          +                       'selectIndex="{{previewIndex}}"'
          +                       'on-item-click="handlePreviewClick"/>'
          +               '</div>'
          +               '<div class="ai-right-tool ai-tool-bar">'
          +                   '<div class="right-blur-mask tool-blur-mask"></div>'
          +                   '<m-tool-button '
          +                       's-show="selectType && hasBrush && (selectType === toolTypeMap[toolType.REPLACE] '
          +                           '|| selectType === toolTypeMap[toolType.REMOVE]'
          +                           '|| selectType === toolTypeMap[toolType.MANUAL]'
          +                           '|| (selectType === toolTypeMap[toolType.WATERMARK] && clickManual))"'
          +                       'style="margin-right: 16px"'
          +                       'on-click="handleClear"'
          +                       'icon="https://psstatic.cdn.bcebos.com/basics/image_fe/clear_white_1705559231000.png" '
          +                       'active-icon="https://psstatic.cdn.bcebos.com/basics/image_fe/clear_active_1705559225000.png"'
          +                       'text="清屏"'
          +                   '/>'
          +                   '<a target="_blank" class="download-wrap" download href="{{downLink}}">'
          +                       '<m-tool-button '
          +                           'on-click="native:handleDownLoad($event)"'
          +                           'icon="https://psstatic.cdn.bcebos.com/basics/image_fe/download_white_1705545868000.png" '
          +                           'active-icon="https://psstatic.cdn.bcebos.com/basics/image_fe/download_active_1705547280000.png"'
          +                           'text="下载"'
          +                       '/>'
          +                   '</a>'
          +               '</div>'
          +           '</div>'
          +       '</div>'
          +       '<div class="ai-sider-wraper">'
          +           '<m-sider '
          +               's-ref="sider"'
          +               'current-status="{{currentStatus}}"'
          +               'origin-img="{{originImg}}"'
          +               'ext-multi="{{extMulti}}"'
          +               'ext-ratio="{{extRatio}}"'
          +               'similar-default="{{similarDefault}}"'
          +               'reborn-default="{{rebornDefault}}"'
          +               'canvas-image="{{canvasImage}}"'
          +               'thumb-img="{{thumbImg}}"'
          +               'query="{{query}}"'
          +               'edit-status="{{editStatus}}"'
          +               'btn-list="{{btnList}}"'
          +               'tool-type="{{toolType}}"'
          +               'tool-type-map="{{toolTypeMap}}"'
          +               'select-type="{{selectType}}"'
          +               'paint-image="{{paintImage}}"'
          +               'has-brush="{{hasBrush}}"'
          +               'stroke-history-index="{{strokeHistoryIndex}}"'
          +               'click-manual="{{clickManual}}"'
          +               'prompt-list="{{promptList}}"'
          +               'current-ratio="{= currentRatio =}"'
          +               'current-multi="{= currentMulti =}"'
          +               'select-ratio-index="{=selectRatioIndex=}"'
          +               'click-cancel="{=clickCancel=}"'
          +               'preview-index="{=previewIndex=}"'
          +               'on-select-type="handleSelectType"'
          +               'on-click-generate="getClickGenerate"'
          +               'on-current-ratio="getCurentRatio"'
          +               'on-current-multi="getCurentMulti"'
          +               'on-change-edit-status="getEditStatus"'
          +               'on-generate-img-list="getGenerateImgList"'
          +               'on-edit-guide="getEditGuide"'
          +               'on-change-create-count="updateCreateCount"'
          +               'on-change-click-manual="updateClickManual"'
          +               'on-task-id="getTaskId"'
          +               'on-progress="getProgress"'
          +               'on-show-replace-guide="showReplaceGuide"'
          +               'on-enter-manual-water-mark="changeManualWaterMark"'
          +               'on-change-stage="changeStage"'
          +               'on-size-change="handleSizeChange"'
          +               'on-brush-preview-change="handleBrushPreviewChange"'
          +               'on-save-history="saveHistory"'
          +           '/>'
          +       '</div>'
          +       '<m-dialog s-if="showDialog"'
          +           'title="{{dialogTitle}}"'
          +           'desc="{{dialogDesc}}"'
          +           'on-close="handleClose"'
          +           'on-cancel="handleCancel"'
          +           'on-confirm="handleConfirm"/>'
          +       '<m-dialog s-if="showPreviewDialog"'
          +           'desc="{{previewDialogDesc}}"'
          +           'id="{{previewDialogId}}"'
          +           'on-close="handlePreviewClose"'
          +           'on-cancel="handlePreviewCancel"'
          +           'on-confirm="handlePreviewDialogConfirm"/>'
          +   '</div>',
      components: {
          'm-sider': Sider,
          'm-scaleButton': ScaleButton,
          'm-clearButton': ClearButton,
          'm-button': ButtonNew,
          'm-img-list-preview': ImgListPreview,
          'm-edit-guide': EditGuide,
          'm-dialog': Dialog,
          'm-loading': Loading,
          'afx-player': afxPlayer,
          'm-tool-button': toolButton
      },
      initData: function () {
          return {
              toolType: {},
              toolTypeMap: {},
              editStatus: {},
  
              extRatio: [],
              extMulti: [],
              similarDefault: 5,
              rebornDefault: 5,
              originImg: {},
              thumbImg: {},
              query: '',
  
              // 当前编辑器的状态
              currentStatus: '',
              selectType: '-1',
              btnList: [],
              imgList: null,
              clickGenerate: false,
  
              // 从画布获取到的数据
              paintImage: null,
  
              canvasImage: {},
              showEditGuide: false,
              guideData: {},
  
              showDialog: false,
              dialogTitle: '',
              dialogDesc: '',
  
              imgContainerW: 0,
              imgContainerH: 0,
              loadingContainerRect: {},
  
              hasBrush: false,
              scale: 1,
              clickManual: false,
  
              brushSize: 50,
  
              promptList: [],
              fingerSelected: false,
              downLink: '',
  
              currentRatio: '',
              selectRatioIndex: -1,
              progress: 0,
              previewIndex: 1,
              isLogin: false,
              // 创作次数
              createCount: 0,
              showReplaceAnime: false,
              animeId: null,
              replaceAfxUrl: 'https://psstatic.cdn.bcebos.com/basics/afx_1699584564000.mp4',
              loadingText: '正在生成',
              // loading是否区分加载状态
              isStage: true,
              downloadActive: false,
              previewDialogDesc: '切换后已涂抹区域不再保留，确定要切换吗？',
              previewDialogId: 'previewDialog',
              brushPreviewStyle: '',
              generatedSelectType: -1,
              isCanvasWrapMounted: false,
              isExit: false,
              isEntry: false,
              // 图片操作历史：属性有：params, strokeHistory, strokeHistoryIndex, previewIndex
              imgHistory: [],
              // 图片历史索引（当前处于历史的什么位置）
              imgHistoryIndex: 0,
              // 图片笔触操作历史，会存入当前历史图片中
              strokeHistory: [],
              // 笔触历史索引（当前处于笔触的什么位置）
              strokeHistoryIndex: -1,
              taskType: '',
              undoEnabled: false,
              redoEnabled: false
          };
      },
  
      computed: {
          isShowTool() {
              var editStatus = this.data.get('editStatus');
              return this.data.get('currentStatus') !== editStatus.LOADING;
          },
  
          imgWrapStyle() {
              var loadingContainerRect = this.data.get('loadingContainerRect');
              var currentStatus = this.data.get('currentStatus');
              var editStatus = this.data.get('editStatus');
              var selectType = this.data.get('selectType');
  
              var toolTypeMap = this.data.get('toolTypeMap');
              var toolType = this.data.get('toolType');
  
              var currentRatio = this.data.get('currentRatio');
              var currentMulti = this.data.get('currentMulti');
              var temp = {
                  width: loadingContainerRect.width + 'px',
                  height: loadingContainerRect.height + 'px',
                  top: loadingContainerRect.top + 'px',
                  left: loadingContainerRect.left + 'px',
                  'background-repeat': 'repeat',
                  'background-size': '40px 40px'
              };
              if (currentRatio || currentMulti) {
                  temp['background-image'] = 'url(https://gips3.baidu.com/it/u=2240009854,1371246613&fm=3028&app=3028&f=PNG&fmt=auto&q=81&size=f80_80)';
                  temp.border = '1px dashed rgba(255, 255, 255, .5)';
              };
              return selectType === toolTypeMap[toolType.EXPAND] ? temp : {};
          },
          isOriginalImg() {
              return this.data.get('originImg.src') === this.data.get('canvasImage.src');
          },
  
          downloadIcon() {
              var downloadActive = this.data.get('downloadActive');
              return downloadActive ?
                  'https://psstatic.cdn.bcebos.com/basics/image_fe/download_active_1705547280000.png'
                  : 'https://psstatic.cdn.bcebos.com/basics/image_fe/download_white_1705545868000.png';
          },
  
          showBrush: function () {
              var selectType = this.data.get('selectType');
              var toolTypeMap = this.data.get('toolTypeMap');
              var toolType = this.data.get('toolType');
              switch (selectType) {
                  case toolTypeMap[toolType.REPLACE]:
                  case toolTypeMap[toolType.REMOVE]:
                  case toolTypeMap[toolType.MANUAL]:
                      return true;
                  default:
                      return false;
              }
          }
      },
      previewData: {},
      attached: function () {
          // 原始图
          var originImg = this.data.get('originImg');
          var selectType = this.data.get('selectType');
          var toolTypeMap = this.data.get('toolTypeMap');
          var toolType = this.data.get('toolType');
          imageEditElement = new ImageEdit('.ai-img-wraper', {
              imageSrc: originImg.src,
              imageWidth: originImg.width,
              imageHeight: originImg.height
          });
  
          // 初始化时，将原图保存入历史
          this.saveHistory({
              params: {
                  query: '',
                  taskId: ''
              }
          });
          var _this = this;
          this.getLoginStatus();
          this.decorateDownLoad(originImg.src);
          imageEditElement.allowWhellZoom(this.data.get('selectType') !== toolTypeMap[toolType.EXPAND]);
          $(window).resize(function () {
              _this.nextTick(function () {
                  _this.getImgContainerRect();
                  imageEditElement && imageEditElement.resize();
                  var canvasImage = _this.data.get('canvasImage');
                  var currentRatio = _this.data.get('currentRatio');
                  if (currentRatio && currentRatio.split(':') && currentRatio.split(':').length) {
                      _this.getLoadingRect(currentRatio.split(':')[0] / currentRatio.split(':')[1]);
                  }
                  else {
                      _this.getLoadingRect(canvasImage.width / canvasImage.height);
                  }
              });
          });
  
          // 默认初始化时候
          this.getImgContainerRect();
          this.getLoadingRect(originImg.width / originImg.height);
          imageEditElement.on('scaleChanged', function (data) {
              _this.data.set('scale', data.scale);
          });
          imageEditElement.on('hideReplaceGuide', function (data) {
              _this.showReplaceGuide(false);
          });
  
          imageEditElement.on('brushEnd', function () {
              _this.data.set('hasBrush', true);
          });
  
          imageEditElement.on('onEntryAnimation', function () {
              _this.data.set('isEntry', true);
          });
  
          // 监听笔触操作，当有操作时，存在4种情况
          // 1、正常操作，需要将用户的新笔触加入历史笔触中
          // 2、撤销过图片，处于历史图片中，这时候需要将当前笔触加入笔触历史中，并抛弃当前索引后的图片
          // 3、撤销过笔触，处于当前图片笔触历史中，这时候需要存入当前这笔操作，并舍弃当前索引后的历史笔触
          // 4、同时发生2、3
          imageEditElement.on('strokeHistoryChange', function (val) {
              var newStrokeHistoryIndex = val.strokeHistoryIndex;
              var newStrokeHistory = val.strokeHistory;
              _this.data.set('strokeHistory', newStrokeHistory);
              var strokeHistoryIndex = _this.data.get('strokeHistoryIndex');
              var imgHistory = _this.data.get('imgHistory');
              var imgHistoryIndex = _this.data.get('imgHistoryIndex');
              // 处于历史中跨图操作，清空当前图片后面的历史图
              if (imgHistoryIndex !== imgHistory.length - 1) {
                  _this.data.set('imgHistory', imgHistory.slice(0, imgHistoryIndex + 1));
              }
              // 处于历史笔触中，在新增笔触时，需要将当前笔触加入历史，并抛弃当前索引后的历史笔触
              if (newStrokeHistoryIndex !== strokeHistoryIndex + 1) {
                  // 因为当前的笔触已经push并更新进了strokeHistory，所以splice从当前索引切割掉新索引前的笔触
                  // 举个例子：之前存在4笔笔触，撤销至第2笔，当前索引为1，再新进行一笔操作，push至5，此时笔触为：[1,2[当前索引],3,4,5[新操作]]
                  // 需要留下[1, 2, 5]，舍弃[3, 4]，则：[1, 2[当前索引], 3, 4, 5[新操作]].splice(2, 2)即可
                  newStrokeHistory.splice(strokeHistoryIndex + 1, newStrokeHistoryIndex - strokeHistoryIndex - 1);
                  _this.data.set('strokeHistory', newStrokeHistory);
                  _this.data.set('strokeHistoryIndex', newStrokeHistory.length - 1);
                  _this.updateStrokeHistory({
                      strokeHistory: newStrokeHistory,
                      strokeHistoryIndex: newStrokeHistory.length - 1
                  });
              }
              else {
                  _this.data.set('strokeHistoryIndex', newStrokeHistoryIndex);
              }
          });
  
          // 监听笔触更新，存储到当前图片的笔触历史中
          this.watch('strokeHistory', function (val) {
              var imgHistoryIndex = _this.data.get('imgHistoryIndex');
              _this.data.set('imgHistory[' + imgHistoryIndex + '].strokeHistory', val);
          });
  
          this.watch('imgHistoryIndex', function () {
              this.checkUndoRedoStatus();
          });
  
          // 监听笔触索引更新，存储到当前图片的笔触索引中
          this.watch('strokeHistoryIndex', function (val) {
              _this.checkUndoRedoStatus();
              _this.data.set('hasBrush', !!(val > -1));
              var imgHistoryIndex = _this.data.get('imgHistoryIndex');
              _this.data.set('imgHistory[' + imgHistoryIndex + '].strokeHistoryIndex', val);
          });
  
          this.watch('canvasImage', function (val) {
              if (imageEditElement) {
                  var _this = this;
                  imageEditElement.updateImage(val);
                  var taskType = _this.data.get('taskType');
                  var strokeHistoryIndex = _this.data.get('strokeHistoryIndex');
                  strokeHistoryIndex === -1 && _this.data.set('hasBrush', false);
                  _this.decorateDownLoad(val.src);
              }
          });
  
          this.watch('currentStatus', function (val) {
              if (val === 'default') {
                  // 重置时 需要吧点击手动去水印的状态清除
                  this.data.set('clickManual', false);
                  imageEditElement && imageEditElement.reset();
                  imageEditElement && imageEditElement.brush(false);
                  _this.data.set('currentRatio', '');
              }
              if (val === 'complete') {
                  _this.updateBrush();
                  _this.data.set('currentRatio', '');
              }
              if (val === 'loading') {
                  // loading 过程中除了画面延展 其他时候 画布图片都需要归位原位
                  if (_this.data.get('selectType') !== toolTypeMap[toolType.EXPAND]) {
                      imageEditElement && imageEditElement.zoom(1);
                      imageEditElement && imageEditElement.resize();
                  }
              }
              else if (val === 'fail') {
                  // 生成失败
              }
          });
  
          if (selectType === toolTypeMap[toolType.REPLACE]
              || selectType === toolTypeMap[toolType.REMOVE]
              || selectType === toolTypeMap[toolType.MANUAL]) {
              imageEditElement.brush(true);
              this.data.set('brushSelected', true);
              this.data.set('brushSize', 50);
          }
          this.getPrompts();
      },
      detached() {
          imageEditElement && imageEditElement.destroy();
      },
  
      updateBrush() {
          var selectType = this.data.get('selectType');
          var toolTypeMap = this.data.get('toolTypeMap');
          var toolType = this.data.get('toolType');
          switch (selectType) {
              case toolTypeMap[toolType.REPLACE]:
              case toolTypeMap[toolType.REMOVE]:
              case toolTypeMap[toolType.MANUAL]:
              case toolTypeMap[toolType.WATERMARK]:
                  imageEditElement && imageEditElement.brush(true);
                  break;
              case toolTypeMap[toolType.EXPAND]:
                  this.data.set('selectRatioIndex', -1);
                  break;
              default:
                  imageEditElement && imageEditElement.brush(false);
                  break;
          }
      },
      /**
       * 当有图片或者笔触操作时，需要判断更新redo、undo按钮状态
       */
      checkUndoRedoStatus: function () {
          var imgHistoryLength = this.data.get('imgHistory').length;
          var imgHistoryIndex = this.data.get('imgHistoryIndex');
          var strokeHistoryLength = this.data.get('strokeHistory').length;
          var strokeHistoryIndex = this.data.get('strokeHistoryIndex');
          var undoEnabled = imgHistoryIndex !== 0 || strokeHistoryIndex !== -1;
          var redoEnabled = (imgHistoryLength > 0 && imgHistoryIndex < imgHistoryLength - 1)
              || (strokeHistoryLength > 0 && strokeHistoryIndex < strokeHistoryLength - 1);
          this.data.set('undoEnabled', undoEnabled);
          this.data.set('redoEnabled', redoEnabled);
          // 图片历史索引处于首位 && 笔触历史索引处于首位时，则无法再撤销
          // 图片历史索引处于末位 && 笔触历史索引处于末位时，则无法再还原
          this.fire('undo-redo-status', {
              undoEnabled,
              redoEnabled
          });
          this.updateBrush();
      },
      exitAnimation: function () {
          return imageEditElement.exitAnimation();
      },
  
      /**
       * 保存入历史
       */
      saveHistory: function (val = {}) {
          var params = val.params;
          var taskType = val.taskType || '';
          var imgHistory = this.data.get('imgHistory');
          var previewImgList = this.data.get('imgList') || [];
          // 从后往前遍历imgHistory,将strokeHistory的长度截断至strokeHistoryIndex索引
          for (var i = imgHistory.length - 1; i > -1; i--) {
              var item = imgHistory[i];
              // 只保留最后两张图的笔触历史
              if (i <= imgHistory.length - MAX_IMAGE_STROKE_NUM) {
                  item.strokeHistory = [];
                  item.strokeHistoryIndex = -1;
              }
              // 只保留最后20个笔触历史
              else if (item.strokeHistoryIndex >= MAX_STROKE_NUM) {
                  item.strokeHistory = item.strokeHistory.slice(0, MAX_STROKE_NUM);
                  item.strokeHistoryIndex = item.strokeHistory.length - 1;
                  item.showToast = true;
              }
              else {
                  item.strokeHistory = item.strokeHistory.slice(0, item.strokeHistoryIndex + 1);
              }
              imgHistory[i] = item;
          }
  
          // 图片新生成时，将当前图片历史添加到imgHistory
          if (taskType !== buttonType.UNDO && taskType !== buttonType.REDO) {
              imgHistory.push({
                  params: {
                      query: params.query,
                      taskId: params.taskId
                  },
                  strokeHistory: val.strokeHistory || [],
                  strokeHistoryIndex: -1,
                  previewImgList,
                  previewIndex: this.data.get('previewIndex') || 0,
                  showToast: false
              });
              if (imgHistory.length > MAX_IMAGE_NUM) {
                  imgHistory.shift();
              }
              this.data.set('imgHistory', imgHistory);
              this.data.set('imgHistoryIndex', imgHistory.length - 1);
              this.data.set('strokeHistory', []);
              this.data.set('strokeHistoryIndex', -1);
          }
      },
  
      /**
       * 处理undo、redo的点击，分为4种情况
       */
      handleUndoRedoClick: function (type) {
          var undoEnabled = this.data.get('undoEnabled');
          var redoEnabled = this.data.get('redoEnabled');
          var imgHistory = this.data.get('imgHistory');
          var message = '';
          if (type === buttonType.UNDO && !undoEnabled) {
              message = imgHistory.length >= MAX_IMAGE_NUM ? redoToastMap.undoLimit : redoToastMap.undoInit;
          }
          else if (type === buttonType.REDO && !redoEnabled) {
              message = redoToastMap.redoInit;
          }
  
          // 发送点击日志
          this.sendLog('click', type, {
              function: this.data.get('selectType'),
              edit_status: this.data.get('currentStatus'),
              message
          });
          if (message) {
              SendToast({
                  message
              });
              // 出toast提醒时，不做其他逻辑操作
              return;
          }
  
          var strokeHistory = this.data.get('strokeHistory');
          var strokeLen = strokeHistory.length;
          var strokeHistoryIndex = this.data.get('strokeHistoryIndex');
          // 笔触撤销：点击undo按钮 && 笔触历史不为空 && 笔触下标大于等于0
          if (type === buttonType.UNDO && strokeLen > 0 && strokeHistoryIndex >= 0) {
              strokeHistoryIndex--;
              var params = strokeHistoryIndex >= 0 ? strokeHistory[strokeHistoryIndex] : null;
              imageEditElement.redrawCanvas(params);
              this.data.set('strokeHistoryIndex', strokeHistoryIndex);
          }
          // 图片撤销：点击undo按钮 && 笔触历史为空 || 图笔触下标已经到达最左边
          else if (type === buttonType.UNDO && (strokeLen === 0 || strokeHistoryIndex === -1)) {
              this.data.set('taskType', type);
              this.handleImgUndo();
          }
          // 笔触还原：点击redo按钮 && 笔触历史不为空 && 笔触下标小于笔触历史长度
          else if (type === buttonType.REDO && strokeLen > 0 && strokeHistoryIndex < strokeLen - 1) {
              strokeHistoryIndex++;
              imageEditElement.redrawCanvas(strokeHistory[strokeHistoryIndex]);
              this.data.set('strokeHistoryIndex', strokeHistoryIndex);
          }
          // 图片还原：点击redo按钮 && 笔触历史为空 || 笔触下标已经到达最右边
          else if (type === buttonType.REDO
              && (strokeLen === 0 || (strokeLen > 0 && strokeHistoryIndex === strokeLen - 1))) {
              this.data.set('taskType', type);
              this.handleImgRedo();
          }
      },
  
      /**
       * 更新历史笔触
       * @param {object} params - 笔触历史和笔触下标
       */
      updateStrokeHistory: function (params) {
          imageEditElement.updateStrokeHistory(params);
      },
  
      /**
       * 处理图片撤销
       */
      handleImgUndo: function () {
          var imgHistoryIndex = this.data.get('imgHistoryIndex');
          var imgHistory = this.data.get('imgHistory');
          this.data.set('imgHistoryIndex', --imgHistoryIndex);
          if (imgHistory[imgHistoryIndex].params.taskId) {
              this.redrawImage(buttonType.UNDO);
          }
          else {
              // 回到原图
              this.fire('update-canvas-image', this.data.get('originImg'));
              this.data.set('imgList', []);
              this.updateBrush();
          }
          this.handleUpdate(buttonType.UNDO);
      },
  
      /**
       * 处理图片还原
       */
      handleImgRedo: function () {
          var imgHistory = this.data.get('imgHistory');
  
          // 历史下标右移
          var imgHistoryIndex = this.data.get('imgHistoryIndex') + 1;
          this.data.set('imgHistoryIndex', imgHistoryIndex);
          this.data.set('strokeHistory', []);
          this.data.set('strokeHistoryIndex', -1);
          var imgHisItem = imgHistory[imgHistoryIndex];
          if (imgHisItem && imgHisItem.params && imgHisItem.params.taskId) {
              this.redrawImage(buttonType.REDO);
          }
          else {
              this.fire('update-canvas-image', this.data.get('originImg'));
              imageEditElement.updateImage(this.data.get('originImg'));
              this.data.set('imgList', []);
              this.updateBrush();
          }
          this.handleUpdate(buttonType.REDO);
      },
  
      /**
       * 重新生成图片
       * @param {string} taskType - 任务类型
       */
      redrawImage: function (taskType) {
          var imgHistoryIndex = this.data.get('imgHistoryIndex');
          var imgHistory = this.data.get('imgHistory');
          var imgHistoryItem = imgHistory[imgHistoryIndex];
          var previewImgList = imgHistory[imgHistoryIndex].previewImgList;
          var previewIndex = imgHistoryItem.previewIndex;
          if (previewImgList.length > 0 && previewIndex <= previewImgList.length - 1) {
              this.data.set('previewIndex', imgHistoryItem.previewIndex);
          }
          this.getGenerateImgList({
              list: previewImgList,
              needUnshift: false,
              generatedSelectType: this.data.get('generatedSelectType'),
              taskType: buttonType.UNDO
          });
      },
  
      /**
       * 清空历史
       */
      clearImgHistory: function () {
          this.data.set('imgHistory', []);
          this.data.set('imgList', []);
          this.data.set('previewIndex', 1);
          // 保存原图入历史
          this.saveHistory({
              params: {
                  query: '',
                  taskId: ''
              }
          });
          this.data.set('imgHistoryIndex', 0);
      },
  
      /**
       * 撤销/还原图片后的一些后置操作
       * @param {string} type - 操作类型
       */
      handleUpdate: function (taskType) {
          var editStatus = this.data.get('editStatus');
          this.data.set('currentStatus', editStatus.COMPLETE);
          var _this = this;
          var imgHistoryIndex = _this.data.get('imgHistoryIndex');
          var imgHistoryItem = _this.data.get('imgHistory')[imgHistoryIndex] || {};
          var curStrokeHistory = (imgHistoryItem && imgHistoryItem.strokeHistory) || [];
          var previewImgList = imgHistoryItem.previewImgList || [];
          var previewIndex = imgHistoryItem.previewIndex;
          if (taskType === buttonType.UNDO) {
              if (imgHistoryItem.showToast) {
                  SendToast({
                      message: redoToastMap.strokeLimit
                  });
              }
              _this.data.set('previewIndex', imgHistoryItem.previewIndex);
              _this.data.set('strokeHistory', curStrokeHistory);
              _this.data.set('strokeHistoryIndex', curStrokeHistory.length - 1);
              // 在图片替换后，再添加笔触历史纪录
              if (curStrokeHistory.length > 0) {
                  setTimeout(function () {
                      _this.updateStrokeHistory({
                          strokeHistory: curStrokeHistory,
                          strokeHistoryIndex: curStrokeHistory.length - 1
                      });
                      imageEditElement.redrawCanvas(curStrokeHistory[curStrokeHistory.length - 1]);
                      _this.updateBrush();
                  }, 50);
              }
          }
  
          // 选中对应缩略图
          if (previewImgList.length > 0) {
              _this.updatePreviewIndex({
                  index: previewIndex,
                  image: previewImgList[previewIndex]
              });
          }
          _this.nextTick(function () {
              _this.updateBrush();
          });
          _this.data.set('taskType', '');
      },
  
      /**
       * 获取当前登录状态
       */
      getLoginStatus: function () {
          var _this = this;
          var isLogin = false;
          $.ajax({
              url: '/user/logininfo?src=pc&page=searchresult&time=' + (new Date).getTime(),
              type: 'GET',
              dataType: 'json'
          })
              .done(function (response) {
                  if (response && response.status && response.status.code === 0) {
                      isLogin = true;
                  }
                  else {
                      isLogin = false;
                  }
              })
              .fail(function () {
                  isLogin = false;
              })
              .always(function () {
                  _this.data.set('isLogin', isLogin);
              });
      },
  
      decorateDownLoad: function (img) {
          if (img.indexOf('data:image/jpeg;base64,') === 0) {
              // 如果含"data:image/jpeg;base64," 则需要自己做截取处理
              var content  = img.indexOf('data:image/jpeg;base64,') === 0 ? img.split('data:image/jpeg;base64,')[1] : '';
              var blob = '';
              if (content) {
                  var raw = window.atob(content);
                  var rawLength = raw.length;
                  var uInt8Array = new Uint8Array(rawLength);
                  for (var i = 0; i < rawLength; ++i) {
                      uInt8Array[i] = raw.charCodeAt(i);
                  }
                  blob = URL.createObjectURL(new Blob([uInt8Array], {type: 'image/jpeg'}));
              }
              blob && this.data.set('downLink', blob);
              return;
          }
          var thumbImg = encodeURIComponent(this.data.get('thumbImg').src);
          var url = encodeURIComponent(img);
          var res = '/search/down?tn=download&word=download&ie=utf8&fr=detail&url=' + url + '&thumburl=' + thumbImg;
          this.data.set('downLink', res);
      },
  
      getPrompts: function () {
          // 这个picInfo 是用的原图的链接
          var _this = this;
          $.get('/aigc/extinfo', {
              picInfo: this.data.get('originImg').src
          }).then(function (res) {
              _this.data.set('promptList', res.descData);
          });
      },
  
      /**
       * 当窗口大小变化时，重新获取图片容器的大小
       */
      getImgContainerRect: function () {
          var rect = $('.ai-img-wrap')
              && $('.ai-img-wrap')[0]
              && $('.ai-img-wrap')[0].getBoundingClientRect();
          if (rect) {
              this.data.set('imgContainerW', rect.width);
              this.data.set('imgContainerH', rect.height);
          }
      },
  
      checkShowGuide: function (type) {
          var btnList = this.data.get('btnList');
          var localGuideCount = JSON.parse(localStorage.getItem(PIC_SEARCH_AI_GUIDE));
          // 引导动画的缓存数据
          var guideMap = {};
  
          if (!localGuideCount) {
              btnList.forEach(function (item) {
                  if (!guideMap[item.type]) {
                      guideMap[item.type] = {
                          count: item.type === type ? 1 : 0,
                          confirmed: false
                      };
                  }
              });
              localStorage.setItem(PIC_SEARCH_AI_GUIDE, JSON.stringify(guideMap));
              return true;
          }
          if (localGuideCount[type]) {
              if (!localGuideCount[type].confirmed && localGuideCount[type].count < 3) {
                  localGuideCount[type].count++;
                  localStorage.setItem(PIC_SEARCH_AI_GUIDE, JSON.stringify(localGuideCount));
                  return true;
              }
              if (localGuideCount[type].confirmed || localGuideCount[type].count >= 3) {
                  return false;
              }
          }
      },
      handleFingerClick: function (status) {
          var selectType = this.data.get('generatedSelectType');
          imageEditElement.move(status);
          // 点击拖拽时如果画笔被选中 则取消画笔被选中状态
          if (!status && this.data.get('showBrush')) {
              imageEditElement.brush(true);
          }
          if (this.data.get('brushSelected')) {
              this.data.set('brushSelected', false);
          }
          this.sendLog('click', 'drag', {
              function: selectType,
              status
          });
      },
  
      handleBrushClick: function (status) {
          imageEditElement.brush(status);
          if (this.data.get('fingerSelected')) {
              this.data.set('fingerSelected', false);
          }
          var selectType = this.data.get('selectType');
          this.sendLog('click', 'brush', {
              function: selectType,
              status
          });
      },
      handleScaleChange: function (data) {
          var scale = data.scale;
          var type = data.type;
          imageEditElement.zoom(scale);
          var logMap = {
              sub: 'narrow',
              add: 'enlarge'
          };
          this.sendLog('click', logMap[type], {
              scale
          });
      },
  
      handleClear: function () {
          this.data.set('showDialog', true);
          this.data.set('dialogTitle', '您确定要清空吗？');
          this.data.set('dialogDesc', '清除将会清空当前图片的操作记录');
          this.sendLog('click', 'clear');
      },
  
      handleClose: function () {
          this.data.set('showDialog', false);
          this.sendLog('click', 'clear', {
              retent_pos: 'close'
          });
      },
      handleCancel: function () {
          this.data.set('showDialog', false);
          this.sendLog('click', 'clear', {
              retent_pos: 'cancel'
          });
      },
      handleConfirm: function () {
          imageEditElement.clearCanvas();
          this.data.set('hasBrush', false);
          this.data.set('showDialog', false);
          var imgHistoryIndex = this.data.get('imgHistoryIndex');
          var imgHistory = this.data.get('imgHistory');
          this.saveHistory({
              params: imgHistory[imgHistoryIndex].params,
              strokeHistory: this.data.get('strokeHistory')
          });
          this.sendLog('click', 'clear', {
              retent_pos: 'confirm'
          });
      },
      handleSizeChange: function (size) {
          imageEditElement.setBrushWidth(size);
          this.data.set('fingerSelected', false);
          imageEditElement && imageEditElement.brush(true);
          this.data.set('brushSize', size);
      },
  
      handleSelectType: function (type) {
          var toolTypeMap = this.data.get('toolTypeMap');
          var toolType = this.data.get('toolType');
          var canvasImage = this.data.get('canvasImage');
          var _this = this;
          this.data.set('generatedSelectType', type);
          this.fire('select-type', type);
          this.data.set('hasBrush', false);
          // 切换工具时需要清空笔触历史
          this.data.set('strokeHistory', []);
          this.data.set('strokeHistoryIndex', -1);
          this.getLoadingRect(canvasImage.width / canvasImage.height);
          // 切换工具 重置下画布 需要等外层容器视图更新之后才可以更新图片
          this.nextTick(function () {
              if (imageEditElement) {
                  // 点击切换时 需要重置画布 且如果是局部替换时需要设置笔刷模式
                  imageEditElement.resize();
                  imageEditElement.reset();
                  imageEditElement.allowWhellZoom(type !== toolTypeMap[toolType.EXPAND]);
                  // 切换type 设置画笔被选中
                  if (type === toolTypeMap[toolType.REPLACE] || type === toolTypeMap[toolType.REMOVE]) {
                      _this.data.set('brushSelected', true);
                      imageEditElement.brush(true);
                  }
                  _this.data.set('brushSize', 50);
                  // 重置小手为未选中状态
                  _this.data.set('fingerSelected', false);
                  // 重置画笔大小 这个50 是默认的画笔大小
                  imageEditElement.setBrushWidth(50);
              }
          });
          var toastOption = {
              message: TOASTMAP[type]
          };
          if (type === toolTypeMap[toolType.REPLACE]) {
              toastOption.duration = replaceToastDuration;
          }
          if (type === toolTypeMap[toolType.REMOVE]) {
              toastOption.duration = removeToastDuration;
          }
          this.data.set('loadingText', LOADINGTEXT[type] || '正在生成');
          TOASTMAP[type] && SendToast(toastOption);
  
          if (type === -1) {
              imageEditElement && imageEditElement.reset();
              this.data.set('fingerSelected', false);
          }
      },
  
      getEditStatus: function (status) {
          this.fire('change-edit-status', status);
      },
  
      handleDownLoad: function (e) {
          var previewIndex = this.data.get('previewIndex');
          this.sendLog('click', 'download', {
              // 看当前用户下载的哪个任务生成的图片
              taskId: this.taskId,
              pos: previewIndex === -1 ? 1 : previewIndex,
              pic_type: this.data.get('isOriginalImg') ? 0 : 1,
          });
          var isLogin = this.data.get('isLogin');
          var createCount = this.data.get('createCount');
          var displayParams = surveyController.displayParams;
          var page = displayParams.page;
          var functionType = displayParams.functionType || [];
          // 如果下载原图不需要登录，当未登录 且 有创作次数(非原图) 且 不是预览第一张图（第一种为原图）时，需要登录
          if (!isLogin && createCount > 0 && previewIndex !== 0) {
  
              // 阻止下载行为
              e.stopPropagation();
              e.preventDefault();
              loginPopup.setSuccessCallback(this.loginSuccess.bind(this));
              loginPopup.setShowCallback(this.loginPopShow.bind(this));
              loginPopup.show();
          }
          else if (page === PAGE.EDIT && functionType.includes('0')) {
              surveyController.show(3);
          }
      },
  
      saveImg: function () {
          $('.download-wrap')[0].click();
      },
  
      loginPopShow: function () {
          this.sendLog('show', 'login');
      },
  
      loginSuccess: function () {
          this.sendLog('show', 'login_success');
          this.saveImg();
          var displayParams = surveyController.displayParams;
          var page = displayParams.page;
          var functionType = displayParams.functionType || [];
          if (page === PAGE.EDIT && functionType.includes('0')) {
              surveyController.show(3);
          }
          this.data.set('isLogin', true);
          this.fire('change-login-status', true);
      },
  
      handleManualWaterMark: function (resType, sendlog) {
          // 默认toast 3
          var resType = parseInt(resType, 10);
          this.fire('click-manual', resType);
          this.data.set('clickManual', true);
          this.data.set('brushSelected', true);
          imageEditElement.brush(true);
          // 重置画笔
          this.data.set('brushSize', 50);
          imageEditElement.setBrushWidth(50);
          if (resType > 0) {
              SendToast({
                  message: WATERMARKTOAST[resType]
              });
          }
          this.showReplaceGuide(true);
  
          var toolTypeMap = this.data.get('toolTypeMap');
          var toolType = this.data.get('toolType');
  
          if (sendlog) {
              this.sendLog('click', 'watermark', {
                  function: toolTypeMap[toolType.MANUAL],
                  edit_status: 'edit'
              });
          }
      },
  
      changeManualWaterMark: function (data) {
          this.handleManualWaterMark(data.resType, data.sendlog);
      },
  
      getCurentRatio: function (data) {
          var originImg = this.data.get('originImg');
          var originImgRatio = originImg.width + ':' + originImg.height;
          var temp = data ? data : originImgRatio;
          this.getLoadingRect(temp.split(':')[0] / temp.split(':')[1]);
          this.nextTick(function () {
              imageEditElement && imageEditElement.resize();
          });
      },
      getCurentMulti: function (data) {
          imageEditElement.zoom(1 / data);
      },
  
      getClickGenerate: function (status) {
          if (status && imageEditElement) {
              var _this = this;
              var canvasImage = this.data.get('canvasImage');
              var originImg = this.data.get('originImg');
              var maskSrc = '';
  
              if (this.data.get('hasBrush')) {
                  maskSrc = imageEditElement.getCanvasDataURL();
              }
              var thumbImg = this.data.get('thumbImg');
              imageEditElement
                  .getBase64Image(thumbImg.src, thumbImg.width, thumbImg.height)
                  .then(function (res) {
                      _this.data.set('tempThumbImg', res);
                      if (canvasImage.src === originImg.src) {
                          _this.data.set('paintImage', {
                              imageSrc: res,
                              maskSrc
                          });
                      }
                      else {
                          _this.data.set('paintImage', {
                              imageSrc: _this.data.get('canvasImage').src,
                              maskSrc
                          });
                      }
                  });
          }
      },
  
      getGenerateImgList: function (data) {
          var list = data.list;
          var needUnshift = data.needUnshift;
          var noRender = data.noRender;
          var generatedSelectType = data.generatedSelectType;
          var taskType = data.taskType;
          this.data.set('generatedSelectType', generatedSelectType);
          if (!list || !list.length) {
              this.data.set('imgList', []);
              return;
          }
  
          if (needUnshift) {
              list.unshift(this.data.get('canvasImage'));
          }
          this.data.set('imgList', list);
          // 非历史操作默认设置为1
          if (taskType !== buttonType.UNDO && taskType !== buttonType.REDO) {
              this.data.set('previewIndex', 1);
          }
          if (noRender) {
              return;
          }
          this.fire('update-canvas-image', list[1]);
          // 生成图片之后更新 当前画布的数据
          this.nextTick(function () {
              imageEditElement.resize();
          });
      },
  
      getTaskId: function (id) {
          this.taskId = id;
      },
  
      getProgress: function (data) {
          this.data.set('progress', data);
      },
  
      changeStage: function (val) {
          this.data.set('isStage', val);
      },
  
      handlePreviewClick: function (data) {
          this.previewData = data;
          var id = this.data.get('previewDialogId');
          if (!localStorage.getItem(id) && this.data.get('hasBrush') && this.data.get('showBrush')) {
              this.data.set('showPreviewDialog', true);
          }
          else {
              this.updatePreviewIndex(data);
              if (this.data.get('showBrush')) {
                  this.nextTick(function () {
                      imageEditElement.brush(true);
                  });
              }
          }
      },
      handlePreviewDialogConfirm: function () {
          this.data.set('showPreviewDialog', false);
          this.updatePreviewIndex(this.previewData);
          // 清空笔触历史
          this.data.set('strokeHistory', []);
          this.data.set('strokeHistoryIndex', -1);
      },
      handlePreviewClose: function () {
          this.data.set('showPreviewDialog', false);
      },
      handlePreviewCancel: function () {
          this.data.set('showPreviewDialog', false);
      },
      updatePreviewIndex(data) {
          this.data.set('previewIndex', data.index);
          var imgHistory = this.data.get('imgHistory');
          var imgHistoryIndex = this.data.get('imgHistoryIndex');
          imgHistory[imgHistoryIndex].previewIndex = data.index;
          this.data.set('imgHistory', imgHistory);
          this.fire('update-canvas-image', data.image);
          imageEditElement.updateImage(data.image);
          // 点击切换图片 如果小手被选中 则需要设置未选中 因更新画布图片之后 所有的交互都重置了
          if (this.data.get('fingerSelected')) {
              this.data.set('fingerSelected', false);
          }
  
          this.sendLog('click', 'preview', {
              image_loc: (data.index > 0) ? 1 : 0,
              tag: data.image && data.image.tag,
              taskId: this.taskId
          });
      },
      getEditGuide: function (data) {
          if (!data.tool) {
              return;
          }
          var showEditGuide = this.checkShowGuide(data.type);
          if (showEditGuide) {
              var _this = this;
              this.nextTick(function () {
                  _this.sendLog('show', 'guide', {
                      function: data.type,
                      edit_status: _this.data.get('currentStatus')
                  });
              });
          }
          this.data.set('showEditGuide', showEditGuide);
          this.data.set('guideData', data.tool);
      },
  
      closeEditGuide: function () {
          var selectType = this.data.get('selectType');
          var btnList = this.data.get('btnList');
          for (var i = 0; i < btnList.length; i++) {
              var item = btnList[i];
              item.confirmed = selectType === item.type;
          }
          this.data.set('btnList', JSON.parse(JSON.stringify(btnList)));
  
          this.sendLog('click', 'guide', {
              function: selectType,
              edit_status: this.data.get('currentStatus')
          });
          var localGuideCount = JSON.parse(localStorage.getItem(PIC_SEARCH_AI_GUIDE));
          localGuideCount[selectType].confirmed = true;
          localStorage.setItem(PIC_SEARCH_AI_GUIDE, JSON.stringify(localGuideCount));
      },
  
      getLoadingRect: function (imgRatio) {
          var innerWidth = this.data.get('imgContainerW');
          var innerHeight = this.data.get('imgContainerH');
          var ratio = innerWidth / innerHeight;
          var width = 0;
          var height = 0;
          if (ratio > imgRatio) {
              width = innerHeight * imgRatio;
              height = innerHeight;
          } else {
              height = innerWidth / imgRatio;
              width = innerWidth;
          }
  
          var canvasWrapTop = (innerHeight - height) / 2;
          var canvasWrapLeft = (innerWidth - width) / 2;
  
          var res = {
              width: width,
              height: height,
              top: canvasWrapTop,
              left: canvasWrapLeft
          };
          this.data.set('loadingContainerRect', res);
          return res;
      },
  
  
      sendLog: function (type, value, extra) {
          var originImg = this.data.get('originImg');
          var query = this.data.get('query');
          var selectType = this.data.get('generatedSelectType');
          var currentStatus = this.data.get('currentStatus');
  
          var ext = $.extend({}, {
              image: originImg.src,
              query,
              function: selectType,
              edit_status: currentStatus
          }, extra);
  
          this.dispatch('send-log', {
              type,
              value,
              ext
          });
      },
  
      updateClickManual: function (status) {
          this.data.set('clickManual', status);
      },
  
      updateCreateCount: function (createCount) {
          this.data.set('createCount', createCount);
      },
  
      showReplaceGuide: function (show) {
          var _this = this;
          if (show) {
              this.data.set('showReplaceAnime', true);
              var id = setTimeout(function () {
                  _this.data.set('showReplaceAnime', false);
              }, replaceToastDuration);
              this.data.set('animeId', id);
          }
          else {
              var id = this.data.get('animeId');
              clearTimeout(id);
              this.data.set('showReplaceAnime', false);
              this.data.set('animeId', null);
          }
      },
      getBtnType: function (type) {
          var toolTypeMap = this.data.get('toolTypeMap');
          return toolTypeMap[type];
      },
      handleMouseDown: function (type) {
          if (type === 'download') {
              this.data.set('downloadActive', true);
          }
      },
      handleMouseUp: function (type) {
          if (type === 'download') {
              this.data.set('downloadActive', false);
          }
      },
      handleMouseLeave: function (type) {
          if (type === 'download') {
              this.data.set('downloadActive', false);
          }
      },
      handleBrushPreviewChange(val) {
          var size = val.size;
          var init = val.init;
          var styleObj = {
              width: size + 'px',
              height: size + 'px',
              display: (size && !init) ? 'block' : 'none',
          };
          this.data.set('brushPreviewStyle', this.getStyleStr(styleObj));
      },
      getStyleStr(obj) {
          var res = '';
          for (var key in obj) {
              res += key + ':' + obj[key] + ';';
          }
          return res;
      }
  });
  

});
